﻿
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;


namespace HDJ.Framework.Core
{
    public class JsonLoadSaveControllerBase<T> 
    {
        public virtual string FullPath
        {
            get
            {
                return "";
            }
        }

        public bool SaveData(T data)
        {
            string json = JsonUtils.ToJson(data);
            return FileUtils.CreateTextFile(FullPath, json);
        }

        public T LoadData()
        {
            string name = Path.GetFileNameWithoutExtension(FullPath);
            if (!ResourceManager.ExistAssets(name))
                return default(T);
           string json=  ResourceManager.LoadText(name);

            return JsonUtils.FromJson<T>(json);
        }
    }
}
